package practice;

import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

/**
 * 英文输入法
 */
public class EnglishInputMethod {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            String str = sc.nextLine();

            String matchStr = sc.nextLine();

            String[] strs = str.split(" ");
            List<String> list = Arrays.stream(strs)
                    .map(s -> Arrays.stream(s.split("'")).collect(Collectors.toList()))
                    .flatMap(List::stream)
                    .filter(s -> s.startsWith(matchStr))
                    .sorted()
                    .collect(Collectors.toList());

            if (list.isEmpty()) {
                System.out.println(matchStr);
            } else {
                list.forEach(s -> System.out.print(s + " "));
            }
        }
    }
}
